package cn.csdj.sism.web;

import cn.csdj.sism.pojo.Student;
import cn.csdj.sism.pojo.Studentscore;
import cn.csdj.sism.service.StudentscoreService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * Controller实现类
 * 李心怡
 * 2023/4/10
 */
@CrossOrigin
@RestController
@RequestMapping("/studentscore")
public class StudentscoreController {
    @Autowired
    private StudentscoreService studentscoreService;
    @PostMapping
    public int insert(@RequestBody Studentscore studentscore){
        if (StringUtils.isEmpty(studentscore.getScoreId())){
            return studentscoreService.insert(studentscore);
        }else {
            return studentscoreService.update(studentscore);
        }
    }
    @DeleteMapping("/{id}")
    public int deleteById(@PathVariable Integer id){
        return studentscoreService.deleteById(id);
    }
    @GetMapping("/{id}")
    public Studentscore selectById(@PathVariable Integer id){
        return studentscoreService.selectById(id);
    }
    @GetMapping
    public List<Studentscore> selectAll(){
        return studentscoreService.selectAll();
    }
    @GetMapping("/page/{current}/{pageSize}")
    public IPage<Studentscore> selectPage(@PathVariable Integer current, @PathVariable Integer pageSize){
        return studentscoreService.selectPages(current,pageSize);
    }
}
